﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Collections.ObjectModel;
using System.Data.SqlClient;
using VisaCRM.Modules.Admin.Model;
using VisaCRM.Common.Helper;

namespace VisaCRM.Modules.Admin.Gateway
{
    class QualificationGateway
    {
        public ObservableCollection<Qualification> GetAllQualification()
        {
            ObservableCollection<Qualification> allQualification = new ObservableCollection<Qualification>();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchQualificationList());
            if (dt.Rows.Count <= 0)
            {
                return allQualification;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                allQualification.Add(new Qualification()
                {
                    QualificationID = Convert.ToInt32(dataRow["Qual_ID"].ToString()),
                    QualificationName = dataRow["Qual_Name"].ToString(),
                    QualificationDegree = Convert.ToInt32(dataRow["Qual_Degree"].ToString()),
                    QualificationCountry = Convert.ToInt32(dataRow["Qual_Country"].ToString()),
                });
            }
            return allQualification;
        }

        public void SaveNewQualificationToDatabase(string qualificationName, int qualificationDegree)
        {
            string query = QueryProvider.MakeSQLQueryToInsertQualificationToDatabase(qualificationName, qualificationDegree);
            DBHelper.ExecuteSqlQuery(query);
        }

        public void EditQualificationToDatabase(string qualificationName, int qualificationDegree, int rowid)
        {
            string query = QueryProvider.MakeSQLQueryToEditQualificationToDatabase(qualificationName, qualificationDegree, rowid);
            DBHelper.ExecuteSqlQuery(query);

        }

        public void DeleteQualificationFromDatabase(int rowid)
        {
            string query = QueryProvider.MakeSQLQueryToDeleteQualificationFromDatabase(rowid);
            DBHelper.ExecuteSqlQuery(query);
        }
    }
}
